package com.lzit.smart_canteen.repository;

import com.lzit.smart_canteen.domain.CartItem;
import com.lzit.smart_canteen.domain.OrderItem;
import jakarta.persistence.criteria.CriteriaBuilder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface CartItemRepository extends JpaRepository<CartItem, Integer> {
    CartItem findCartItemByFid(Integer fid);

    @Transactional
    @Modifying
    @Query(value = "UPDATE t_cart_item SET count=?3 WHERE fid=?2 AND uid=?1", nativeQuery = true)
    void updateCountByUidAndFid(Integer uid,Integer fid, Integer count);
    @Transactional
    @Modifying
    void deleteCartItemByUidAndFid(Integer uid, Integer fid);
    @Transactional
    @Modifying
    void deleteCartItemByUid(Integer uid);

    List<CartItem> findCartItemsByUid(Integer uid);
    CartItem findCartItemByUidAndFid(Integer uid,Integer fid);

}
